; docformat = 'rst'
;
;+
;
; :Purpose:
;   Create MOZART initial conditions file
;   
; :Inputs:
;   var: 3D initial conditions field in kg/kg
;   outfile: initial conditions file name
;   
; :Example::
;   
;   GAUGE_MOZART_initial_conditions, CO2, '/my/MOZART/directory/mf_file.nc'
;
; :History:
; 	Written by: Matt Rigby, University of Bristol, Mar 13, 2014
;
;-
pro GAUGE_MOZART_initial_conditions, var, varID, outfile, date=date, UTC=UTC

  callStack=Scope_Traceback()
  directory=strmid(callStack[-1], strPos(callStack[-1], '<')+1)
  directory=strmid(directory, 0, strPos(directory, '/', /reverse_search)+1)

  file_copy, strcompress(directory + 'ic_template.nc'), outfile, /overwrite

  if n_elements(varID) eq 1 then begin
    mr_ncput, var, varID, dimensions=['lon', 'lat', 'lev'], $
      filename=outfile, attributes=['units', 'kg/kg']
  endif else begin
    foreach id, varID, i do begin
      mr_ncput, reform(var[i, *, *, *]), id, dimensions=['lon', 'lat', 'lev'], $
        filename=outfile, attributes=['units', 'kg/kg']
    endforeach
  endelse

  if keyword_set(date) then begin
    mr_ncput, date, 'date', filename=outfile
  endif

  if keyword_set(UTC) then begin
    mr_ncput, UTC, 'datesec', filename=outfile
  endif

end